﻿using System.ComponentModel;
using System;
using System.Windows;
using GalaSoft.MvvmLight.Messaging;

namespace WP7Client.Controller
{
    public class BaseController : DependencyObject, INotifyPropertyChanged
    {
        #region Members

        public event PropertyChangedEventHandler PropertyChanged;

        public Boolean _Loading;

        #endregion

        #region Get&Set

        public Boolean Loading
        {
            get { return _Loading; }
            set
            {
                _Loading = value;
                OnPropertyChanged("Loading");
            }
        }

        #endregion

        public virtual void Update() { }

        protected void OnPropertyChanged(string propertyName)
        {
            var eventCopy = PropertyChanged;
            if (eventCopy == null)
                return;

            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                eventCopy(this, new PropertyChangedEventArgs(propertyName));
            });
        }
    }
}
